package io.awen.modules.sign.controller;

import io.awen.common.utils.PageUtils;
import io.awen.common.utils.R;
import io.awen.modules.sign.entity.SignCarDispatchEntity;
import io.awen.modules.sign.qo.SignCarDispatchQo;
import io.awen.modules.sign.service.SignCarDispatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;



/**
 * 车辆调度表(用于用户主动调度,改变执行任务的车辆)
 *
 * @author liu.wen
 * @email liu.wen@qq.com
 * @date 2022-08-10 00:47:08
 */
@Api(tags = {"任务调度"})
@RestController
@RequestMapping("sign/signcardispatch")
public class SignCarDispatchController {
    @Autowired
    private SignCarDispatchService signCarDispatchService;

    /**
     * 按条件查询 任务调度 总数
     * @param qo
     * @return
     */
    @PostMapping("/total")
    public R total(@RequestBody SignCarDispatchQo qo){
        int total = signCarDispatchService.total(qo);
        return R.ok().put("total", total);
    }

    /**
     * 按条件查询 任务调度 处理的总收运量
     * @param qo
     * @return
     */
    @PostMapping("/weightTotal")
    public R weightTotal(@RequestBody SignCarDispatchQo qo){
        Double total = signCarDispatchService.weightTotal(qo);
        return R.ok().put("total", total);
    }


    @ApiOperation("手动调度")
    @PostMapping("/manual")
//    @RequiresPermissions("sign:signcardispatch:manual")
    public R manualDispatch(@RequestBody SignCarDispatchEntity dispatch){

        signCarDispatchService.manualDispatch(dispatch);
        return R.ok();
    }

    @ApiOperation("等待手动调度任务的调度列表")
    @PostMapping("/waitmanual/list")
//    @RequiresPermissions("sign:signcardispatch:waited")
    public R waitManualList(@RequestBody SignCarDispatchQo qo){
        List<SignCarDispatchEntity> list = signCarDispatchService.waitManualList(qo);
        return R.ok().put("list", list);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sign:signcardispatch:list")
    public R list(@RequestBody SignCarDispatchQo qo){
        PageUtils page = signCarDispatchService.queryPage(qo);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sign:signcardispatch:info")
    public R info(@PathVariable("id") Long id){
		SignCarDispatchEntity signCarDispatch = signCarDispatchService.getById(id);

        return R.ok().put("signCarDispatch", signCarDispatch);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sign:signcardispatch:save")
    public R save(@RequestBody SignCarDispatchEntity signCarDispatch){
		signCarDispatchService.save(signCarDispatch);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sign:signcardispatch:update")
    public R update(@RequestBody SignCarDispatchEntity signCarDispatch){
		signCarDispatchService.updateById(signCarDispatch);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sign:signcardispatch:delete")
    public R delete(@RequestBody Long[] ids){
		signCarDispatchService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
